package com.sf.sgs.sessionevaluate.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Component;

import com.sf.sgs.sessionevaluate.dao.IQuestionOptionDao;
import com.sf.sgs.sessionevaluate.domain.Question;
import com.sf.sgs.sessionevaluate.domain.QuestionOption;
import com.sf.sgs.sessionevaluate.service.IQuestionOptionService;

@Component
public class QuestionOptionServiceImpl extends TransactionalService implements IQuestionOptionService {

	@Autowired
	private IQuestionOptionDao questionOptionDao;

	@Override
	public QuestionOption getById(Long id) {
		return questionOptionDao.findOne(id);
	}

	@Override
	public List<QuestionOption> getByQuestionId(Long questionId) {
		QuestionOption questionOption = new QuestionOption();
		Question question = new Question();
		question.setId(questionId);
		questionOption.setQuestion(question);
		Example<QuestionOption> example = Example.of(questionOption);
		Sort sort = new Sort(Direction.ASC, "orderIndex");
		return questionOptionDao.findAll(example, sort);
	}

}
